package com.java8.Base64;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * <p>Description: [base64 编码格式 与解码]</p>
 * Created on 2020/5/25
 *
 * @author <a href="mailto: 819712047@qq.com">谢振东 </a>
 * @version 1.0
 */
public class Base64Code {

    public static void main(String[] args) {
        String str = "demo";
        //base64 encoded 把str转换成base64 bytes
        String encoded = Base64.getEncoder().encodeToString(str.getBytes(StandardCharsets.UTF_8));
        System.out.println("encoded:" + encoded);

        //base64 decoded
        String decoded = new String(Base64.getDecoder().decode(encoded), StandardCharsets.UTF_8);
        System.out.println("decoded:" + decoded);
    }
}
